/*This do-file produces interpolated day-by-day estimates of the public image of the EU in all EU countries
for the period October 2004 to end of 2017 from the Eurobarometer survey series.

Please install the carryforward command to run this do-file.

In order for this script to run, you have to download all relevant Eurobarometer data from GESIS. The Eurobarometers 
and corresponding dta-files you need are listed below:

Eurobarometer 62.0 -- ZA4229_v1-1-0.dta
Eurobarometer 63.4 -- ZA4411_v1-1-0.dta
Eurobarometer 64.2 -- ZA4414_v1-1-0.dta ##Depending on your STATA version you may be unable to load this file and have to reduce its size before loading into STATA
Eurobarometer 65.2 -- ZA4506_v1-0-1.dta ##Depending on your STATA version you may be unable to load this file and have to reduce its size before loading into STATA
Eurobarometer 66.1 -- ZA4526_v1-0-1.dta
Eurobarometer 67.2 -- ZA4530_v2-1-0.dta
Eurobarometer 68.1 -- ZA4565_v4-0-1.dta ##Depending on your STATA version you may be unable to load this file and have to reduce its size before loading into STATA
Eurobarometer 69.2 -- ZA4744_v5-0-0.dta
Eurobarometer 70.1 -- ZA4819_v3-0-2.dta
Eurobarometer 71.1 -- ZA4971_v4-0-0.dta
Eurobarometer 72.4 -- ZA4994_v3-0-0.dta
Eurobarometer 73.4 -- ZA5234_v2-0-1.dta
Eurobarometer 74.2 -- ZA5449_v2-2-0.dta
Eurobarometer 75.3 -- ZA5481_v2-0-1.dta
Eurobarometer 76.3 -- ZA5567_v1-0-0.dta
Eurobarometer 77.3 -- ZA5612_v1-0-0.dta
Eurobarometer 78.1 -- ZA5685_v1-0-0.dta
Eurobarometer 79.3 -- ZA5689_v1-0-0.dta
Eurobarometer 80.1 -- ZA5876_v1-0-0.dta
Eurobarometer 81.2 -- ZA5913_v1-0-0.dta
Eurobarometer 82.3 -- ZA5932_v2-0-1.dta
Eurobarometer 83.3 -- ZA5998_v1-1-0.dta
Eurobarometer 84.3 -- ZA6643_v3-1-0.dta
Eurobarometer 85.2 -- ZA6694_v1-1-0.dta
Eurobarometer 86.2 -- ZA6788_v1-2-0.dta
Eurobarometer 87.3 -- ZA6863_v1-0-0.dta
Eurobarometer 88.3 -- ZA6928_v1-0-0.dta
Eurobarometer 89.1 -- ZA6963_v1-0-0.dta
*/

//Set working directory, which should contain all Eurobarometer data files
//cd "YOUR WORKING DIRECTORY WITH ALL EUROBAROMETER FILES"


//Load public opinion data: Eurobarometer 62.0 ZA 4229
use "ZA4229_v1-1-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v102 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork 
gen start_date = date("02/10/2004", "DMY")

save "eb2004_2.dta", replace


//Load public opinion data: Eurobarometer 63.4 ZA 4411
use "ZA4411_v1-1-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v87 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("09/05/2005", "DMY")

save "eb2005_1.dta", replace


//Load public opinion data: Eurobarometer 64.2 ZA 4414
use "ZA4414_v1-1-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v116 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("11/10/2005", "DMY")

save "eb2005_2.dta", replace


//Load public opinion data: Eurobarometer 65.2 ZA 4506
use "ZA4506_v1-0-1.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v97 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("27/03/2006", "DMY")

save "eb2006_1.dta", replace


//Load public opinion data: Eurobarometer 66.1 ZA 4526
use "ZA4526_v1-0-1.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v114 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("06/09/2006", "DMY")

save "eb2006_2.dta", replace


//Load public opinion data: Eurobarometer 67.2 ZA 4530
use "ZA4530_v2-1-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v129 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("10/04/2007", "DMY")

save "eb2007_1.dta", replace


//Load public opinion data: Eurobarometer 68.1 ZA 4565
use "ZA4565_v4-0-1.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v181 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("22/09/2007", "DMY")

save "eb2007_2.dta", replace


//Load public opinion data: Eurobarometer 69.2 ZA 4744
use "ZA4744_v5-0-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v217 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("25/03/2008", "DMY")

save "eb2008_1.dta", replace


//Load public opinion data: Eurobarometer 70.1 ZA 4819
use "ZA4819_v3-0-2.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Image
rename v233 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("06/10/2008", "DMY")

save "eb2008_2.dta", replace


//Load public opinion data: Eurobarometer 71.1 ZA 4971
use "ZA4971_v4-0-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v196 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("16/01/2009", "DMY")

save "eb2009_1.dta", replace


//Load public opinion data: Eurobarometer 72.4 ZA 4994
use "ZA4994_v3-0-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v220 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("24/10/2009", "DMY")

save "eb2009_2.dta", replace


//Load public opinion data: Eurobarometer 73.4 ZA 5234
use "ZA5234_v2-0-1.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v276 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("05/05/2010", "DMY")

save "eb2010_1.dta", replace


//Load public opinion data: Eurobarometer 74.2 ZA 5449
use "ZA5449_v2-2-0.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v305 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start_date of fieldwork
gen start_date = date("11/11/2010", "DMY")

save "eb2010_2.dta", replace


//Load public opinion data: Eurobarometer 75.3 ZA 5481
use "ZA5481_v2-0-1.dta", clear

//Streamline nation labels
rename v7 nation
replace nation = lower(nation)
replace nation = "el" if nation == "gr"
replace v8 = v10 if nation == "gb-gbn"
replace v8 = v10 if nation == "gb-nir"
replace nation = "uk" if nation == "gb-gbn"
replace nation = "uk" if nation == "gb-nir"
replace v8 = v12 if nation == "de-e"
replace v8 = v12 if nation == "de-w"
replace nation = "de" if nation == "de-e"
replace nation = "de" if nation == "de-w"
replace nation = "bu" if nation == "bg"

//Recode public opinion variables

//Image
rename v314 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = v8], by(nation)

//Create start date of fieldwork
gen start_date = date("06/05/2011", "DMY")

save "eb2011_1.dta", replace


//Load public opinion data: Eurobarometer 76.3 ZA 5567
use "ZA5567_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa11 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("05/11/2011", "DMY")

save "eb2011_2.dta", replace


//Load public opinion data: Eurobarometer 77.3 ZA 5612
use "ZA5612_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa14 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("12/05/2012", "DMY")

save "eb2012_1.dta", replace


//Load public opinion data: Eurobarometer 78.1 ZA 5685
use "ZA5685_v1-0-0.dta", clear

//Streamline nation labels
rename COUNTRY nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa12 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of survey
gen start_date = date("03/11/2012", "DMY")

save "eb2012_2.dta", replace


//Load public opinion data: Eurobarometer 79.3 ZA 5689
use "ZA5689_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
drop nation
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa13 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("10/05/2013", "DMY")

save "eb2013_1.dta", replace


//Load public opinion data: Eurobarometer 80.1 ZA 5876
use "ZA5876_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa11 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("02/11/2013", "DMY")

save "eb2013_2.dta", replace


//Load public opinion data: Eurobarometer 81.2 ZA 5913
use "ZA5913_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa8 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("15/03/2014", "DMY")

save "eb2014_1.dta", replace


//Load public opinion data: Eurobarometer 82.3 ZA 5932
use "ZA5932_v2-0-1.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("08/11/2014", "DMY")

save "eb2014_2.dta", replace


//Load public opinion data: Eurobarometer 83.3 ZA 5998
use "ZA5998_v1-1-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("16/05/2015", "DMY")

save "eb2015_1.dta", replace


//Load public opinion data: Eurobarometer 84.3 ZA 6643
use "ZA6643_v3-1-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("07/11/2015", "DMY")

save "eb2015_2.dta", replace


//Load public opinion data: Eurobarometer 85.2 ZA 6694
use "ZA6694_v1-1-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("21/05/2016", "DMY")

save "eb2016_1.dta", replace


//Load public opinion data: Eurobarometer 86.2 ZA 6788
use "ZA6788_v1-2-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("03/11/2016", "DMY")

save "eb2016_2.dta", replace


//Load public opinion data: Eurobarometer 87.3 ZA 6863
use "ZA6863_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("20/05/2017", "DMY")

save "eb2017_1.dta", replace


//Load public opinion data: Eurobarometer 88.3 ZA 6928
use "ZA6928_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("05/11/2017", "DMY")

save "eb2017_2.dta", replace


//Load public opinion data: Eurobarometer 89.1 ZA 6963
use "ZA6963_v1-0-0.dta", clear

//Streamline nation labels
rename country nation2
gen nation = ""
replace nation = "el" if nation2 == 11
replace nation = "uk" if nation2 == 9
replace nation = "uk" if nation2 == 10
replace nation = "es" if nation2 == 12
replace nation = "de" if nation2 == 4
replace nation = "de" if nation2 == 14
replace nation = "mt" if nation2 == 25
replace nation = "bu" if nation2 == 29
replace nation = "at" if nation2 == 18
replace nation = "be" if nation2 == 2
replace nation = "cy" if nation2 == 19
replace nation = "cz" if nation2 == 20
replace nation = "dk" if nation2 == 7
replace nation = "ee" if nation2 == 21
replace nation = "fi" if nation2 == 16
replace nation = "fr" if nation2 == 1
replace nation = "hu" if nation2 == 22
replace nation = "ie" if nation2 == 8
replace nation = "it" if nation2 == 5
replace nation = "lv" if nation2 == 23
replace nation = "lt" if nation2 == 24
replace nation = "lu" if nation2 == 6
replace nation = "nl" if nation2 == 3
replace nation = "pl" if nation2 == 26
replace nation = "pt" if nation2 == 13
replace nation = "ro" if nation2 == 30
replace nation = "si" if nation2 == 28
replace nation = "sk" if nation2 == 27
replace nation = "se" if nation2 == 17
replace nation = "hr" if nation2 == 32
drop if nation == ""

replace w1 = w3 if nation == "de"
replace w1 = w4 if nation == "uk"

//Recode public opinion variables

//Image
rename qa9 image_aux
recode image_aux (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1) (6 = .), gen(image)
drop image_aux

//Collapse dataset by country 
collapse (mean) image [pweight = w1], by(nation)

//Create start date of fieldwork
gen start_date = date("13/03/2018", "DMY")

save "eb2018_1.dta", replace



//Merge all public opinion data

merge 1:1 nation start_date using "eb2004_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2005_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2005_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2006_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2006_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2007_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2007_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2008_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2008_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2009_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2009_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2010_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2010_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2011_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2011_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2012_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2012_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2013_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2013_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2014_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2014_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2015_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2015_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2016_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2016_2.dta"
drop _merge

merge 1:1 nation start_date using "eb2017_1.dta"
drop _merge

merge 1:1 nation start_date using "eb2017_2.dta"
drop _merge


//Save data
save "eb_responsiveness.dta", replace



/*The following section creates a time series of public opinion on the day level
___________________________
___________________________
___________________________

*/

//Get rid of superfluent observations / countries not EU member
drop if nation == " "
drop if nation == ""
drop if nation == "."
drop if nation == "cy-tcc"
drop if nation == "is"
drop if nation == "me"
drop if nation == "mk"
drop if nation == "tr"

//Assign right format for dates
format start_date %d

//Bring to day level and fill in
sort nation start_date
encode nation, gen(country)
xtset country start_date

//Fill in day level observations
tsfill

//Create year indicator
gen year = year(start_date)
label variable year "Year" 

//Order variables
order nation country start_date year image, first

//Fill in missing values by carrying forward values and linear interpolation
sort country start_date
bysort country: carryforward nation, replace
bysort country: ipolate image start_date, gen(image_ipol)

//Create half year lagged variable
sort country start_date
by country: gen image_lag6m = image_ipol[_n-182] if start_date==start_date[_n-182]+182

//Label variables
label variable nation "Country (str)"
label variable country "Country (int)"
label variable start_date "Date"
label variable image_lag6m "Image of EU (1-5), 6-month lag"
label variable image_ipol "Image of EU (1-5)"

//Save data
keep nation country start_date year image_lag6m image_ipol
save "eb_responsiveness_apsr.dta", replace
